package com.bj.dz.service.impl;

import com.bj.dz.entity.CorrespondTvTower;
import com.bj.dz.mapper.CorrespondTvTowerMapper;
import com.bj.dz.service.CorrespondTvTowerService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class CorrespondTvTowerServiceImpl implements CorrespondTvTowerService {

    @Resource
    private CorrespondTvTowerMapper correspondTvTowerMapper;

    public CorrespondTvTower getCorrespondTvTowerById(Integer id){
        return correspondTvTowerMapper.getCorrespondTvTowerById(id);
    }

    public List<CorrespondTvTower>	getCorrespondTvTowerListByMap(Map<String,Object> param){
        return correspondTvTowerMapper.getCorrespondTvTowerListByMap(param);
    }

    public Integer getCorrespondTvTowerCountByMap(Map<String,Object> param){
        return correspondTvTowerMapper.getCorrespondTvTowerCountByMap(param);
    }

    @Transactional
    public boolean addCorrespondTvTower(CorrespondTvTower correspondTvTower){
            return correspondTvTowerMapper.insertCorrespondTvTower(correspondTvTower)>0?true:false;
    }

    @Transactional
    public boolean modifyCorrespondTvTower(CorrespondTvTower correspondTvTower){
        return correspondTvTowerMapper.updateCorrespondTvTower(correspondTvTower)>0?true:false;
    }

    @Transactional
    public boolean deleteCorrespondTvTowerById(Integer id){
        return correspondTvTowerMapper.deleteCorrespondTvTowerById(id)>0?true:false;
    }

    public Page<CorrespondTvTower> queryCorrespondTvTowerPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = correspondTvTowerMapper.getCorrespondTvTowerCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<CorrespondTvTower> correspondTvTowerList = correspondTvTowerMapper.getCorrespondTvTowerListByMap(param);
        page.setRows(correspondTvTowerList);
        return page;
    }

}
